<template>
  <div>
    <!-- table -->
    <a-card style="margin-top: 24px;overflow-x: scroll;">
      <div class="table-operator">
        <div style="margin-bottom:15px;">
          <a-range-picker @change="handleClickChangeDate" :style="{marginLeft:'10px',width: '256px'}" />
          <a-button style="margin-left:10px;">
            <a target="_blank" :href="$hostServer+'/admin/export/day_report?api_token='+curr_token+'&date_str'+date_str">导出Excel</a>
          </a-button>
        </div>
      </div>
      <a-table
        :columns="columns"
        :dataSource="data"
        :pagination="false"
        :loading="dataLoading"
      >
        <template slot="money" slot-scope="text">
          <span v-if="text>0">{{text}}</span>
          <span v-else style="color:red;">{{text}}</span>
        </template>
        <template slot="money_all" slot-scope="text, record">
          <span>{{(record.vip_order_money + record.vip_sub_order_money + record.vip_sub_recharge_money + record.not_vip_money).toFixed(2)}}</span>
        </template>
        <template slot="status" slot-scope="text">
          <template v-if="text==0">
            <template>审核</template>
          </template>
          <template v-else-if="text==1">
            <span style="color:blue">清算</span>
          </template>
          <template v-else-if="text==2">
            <span style="color:green">打款</span>
          </template>
          <template v-else-if="text==3">
            <span style="color:green">完成</span>
          </template>
          <template v-else>
            <span style="color:red">失败</span>
          </template>
        </template>
<!--        <template slot="text" slot-scope="text, record">-->
<!--          <template>-->
<!--            <span>{{text}}</span>-->
<!--          </template>-->
<!--        </template>-->
<!--        <template slot="operation" slot-scope="text, record">-->
<!--          <span>-->
<!--            <a-popconfirm title=this.$t('day_reportList.sfysccx') @confirm="handleClickDelete(record.id)">-->
<!--              <a-button type="danger" size="small">删除</a-button>-->
<!--            </a-popconfirm>-->
<!--          </span>-->
<!--        </template>-->
      </a-table>
      <div style="margin-top:15px;">
        <MyPage :curr="page.curr" :size="page.size" :all="page.total" @changePage="handleChangePage" @changePageSize="handleChangePageSize"/>
      </div>
    </a-card>
    <DialogImg :img_url="curr_img_url" :is_show="curr_img_show"/>
  </div>
</template>

<script>
import { mixin, mixinDevice } from '@/utils/mixin'
import DialogImg from '../../components/DialogImg'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import MyPage from './Page'

export default {
  name: 'AdvancedForm',
  mixins: [mixin, mixinDevice],
  components: {
    DialogImg,
    MyPage
  },
  data () {
    return {
      description: this.$t('day_reportList.mrjsqytdrjbb'),
      loading: false,
      dataLoading: false,
      curr_img_url: '',
      curr_img_show: false,
      stat: [
        0, 0, 0, 0, 0, 0
      ],
      // table
      columns: [
        {
          title: this.$t('day_reportList.rq'),
          dataIndex: 'date_at',
          key: 'date_at'
        },
        {
          title: this.$t('day_reportList.zcrs'),
          dataIndex: 'reg_cnt',
          key: 'reg_cnt'
        },
        {
          title: this.$t('day_reportList.czrs'),
          dataIndex: 'recharge_cnt',
          key: 'recharge_cnt'
        },
        {
          title: this.$t('day_reportList.czje'),
          dataIndex: 'recharge_money',
          key: 'recharge_money'
        },
        {
          title: this.$t('day_reportList.txje'),
          dataIndex: 'withdraw_money',
          key: 'withdraw_money'
        },
        {
          title: this.$t('day_reportList.psyl'),
          dataIndex: 'money',
          key: 'money',
          scopedSlots: { customRender: 'money' }
        },
        {
          title: this.$t('day_reportList.hyztc'),
          dataIndex: 'money',
          key: 'money',
          scopedSlots: { customRender: 'money_all' }
        },
        {
          title: this.$t('day_reportList.hylrtc'),
          dataIndex: 'vip_sub_recharge_money',
          key: 'vip_sub_recharge_money'
        },
        {
          title: this.$t('day_reportList.hyrwtc'),
          dataIndex: 'vip_order_money',
          key: 'vip_order_money'
        },
        {
          title: this.$t('day_reportList.hyxjrwtc'),
          dataIndex: 'vip_sub_order_money',
          key: 'vip_sub_order_money'
        },
        {
          title: this.$t('day_reportList.fhyrwtc'),
          dataIndex: 'not_vip_money',
          key: 'not_vip_money'
        }
        // {
        //   title: this.$t('day_reportList.cz'),
        //   key: 'action',
        //   scopedSlots: { customRender: 'operation' }
        // }
      ],
      data: [],
      errors: [],
      readyCnt: 0,
      runningCnt: 0,
      stopCnt: 0,
      curr_type: -1,
      curr_status: -2,
      curr_token: '',
      map_str: '',
      selectedId: [],
      loadingConfirm: false,
      page: {
        curr: 1,
        size: 20,
        total: 0
      },
      searchUsername: '',
      date_str: '',
      author: ''
    }
  },
  created () {
    this.getList()
    this.curr_token = this.$ls.get(ACCESS_TOKEN)
  },
  methods: {
    onSelectChange (selectedRowKeys) {
      this.selectedId = []
      for (let i = 0; i < selectedRowKeys.length; i++) {
        this.selectedId.push(this.data[selectedRowKeys[i]].id)
      }
      console.log(this.selectedId)
    },
    getList () {
      let url = '/day_report/list?page=' + this.page.curr + '&size=' + this.page.size
      if (this.date_str) {
        url += '&date_str=' + this.date_str
      }
      this.dataLoading = true
      this.$http.get(url).then(res => {
        this.data = res.list
        this.page.total = res.total
      }).catch(err => {
        this.$notification.error({
          message: this.$t('day_reportList.sb'),
          description: err.message
        })
      }).then(() => {
        this.dataLoading = false
      })
    },
    handleClickChangeDate (e, str) {
      this.date_str = str
      this.getList()
    },
    handleChangePageSize (size) {
      this.page.size = size
      this.getList()
    },
    handleChangePage (page) {
      this.page.curr = page
      this.getList()
    }
  }
}
</script>

<style lang="less" scoped>
  .card{
    margin-bottom: 24px;
  }
</style>
